package com.hao.hospital.weixin.api;

public class WeiXinAPI {
	//获取accessToken API
	private static final String ACCESS_TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
	//创建菜单 API
	private static final String CREATE_MENU_URL="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s";
	//第一步，获取code
	private static final String FIRST_GET_CODE="https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=STATE#wechat_redirect";
	//第二步，获取到accessToken(用户授权的access_token)
	private static final String SECOND_GET_ACCESSTOKEN="https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
	//第三部，通过accessToken和openid获取用户信息
	private static final String THIRD_GET_USER_INFO="https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN ";
	/**
	 * 创建菜单
	 * @param accessToken
	 * @return
	 */
	public  static String CreateMenuURL(String accessToken){
		return String.format(CREATE_MENU_URL, accessToken);
	}
	/**
	 * 获取token
	 * @param appid
	 * @param appsecret
	 * @return
	 */
	public static String GetAccessToken(String appid,String appsecret){
		return String.format(ACCESS_TOKEN_URL,appid, appsecret);
	}
	/**
	 * 用户授权第一步，获取code
	 * @param appid
	 * @param redirectUri
	 * @param scope
	 * @return
	 */
	public static String GetCode(String appid,String redirectUri,String scope){
		return String.format(FIRST_GET_CODE, appid,redirectUri,scope);
	}
	/**
	 * 用户授权第二步,获取到accessToken和refreshAccessToken
	 * @param appid
	 * @param secret
	 * @param code
	 * @return
	 */
	public static String GetUserAccessToken(String appid,String secret,String code){
		return String.format(SECOND_GET_ACCESSTOKEN, appid,secret,code);
	}
	/**
	 * 
	 * @param accessToken
	 * @param openid
	 * @return
	 */
	public static String GetUserInfo(String accessToken,String openid){
		return String.format(THIRD_GET_USER_INFO, accessToken,openid);
	}
}
